home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Newton / Utilities / Sieve 1.0.sit / Sieve.nwt < prev    next >
Encoding:
Text File  |  1995-05-21  |  3.2 KB  |  137 lines  |  [TEXT/NWPM]

  1. Sieve
  2. // :doObj('add,'Sieve)
  3. // :doObj('build,'Sieve)
  4. // :doObj('remove,'Sieve)
  5. {
  6. // ---------------------------------------------------------------------------------------
  7. // Freeware...
  8. //   The standard sieve benchmark for the Newton.
  9. //   Info: Runs in about 143 seconds on my OMP.
  10. //  Runs in about 65 seconds on my MP100.
  11. //
  12. //   Thanks to Steve Weyer for explaining a few things
  13. //   and making some suggestions about the GoBtn object
  14. //
  15. // Ver 0.3 9/17/94 -RunNewt
  16. // Ver 1.0 5/18/95 - Newt 3.0
  17. // ---------------------------------------------------------------------------------------
  18.     _proto: 'protoApp,
  19.     title: "Sieve",
  20.     ViewBounds: RelBounds(0,10,220,100),
  21.     _package: {
  22.         version: 100,
  23.         copyright: "©1994,1995 S.Koren.  All rights reserved.", 
  24.     icon: :GetIcon("Sieve"),
  25.     devSignature: "SKoren",
  26. },
  27.     
  28. }
  29. -----
  30. Sieve+about
  31. {
  32.         _proto: 'protoFloatNGo,
  33.      viewBounds:RelBounds(5,5,200,90),
  34. }
  35.  
  36. -----
  37. Sieve+AboutBtn
  38. {_proto: 'protoTextButton,
  39.     text: "About...",
  40.     viewBounds: RelBounds(5,5,60,16),
  41.     buttonClickScript:func()
  42.         about:open();
  43.     
  44. }
  45.  
  46. -----
  47. Sieve+SStatus
  48. {
  49.         _proto: 'protoStaticText,
  50.         viewBounds: RelBounds(20,30,200,16),
  51.         text:  "Prime benchmark."
  52. }
  53.  
  54. -----
  55. Sieve+Status
  56. {
  57.         _proto: 'protoStaticText,
  58.         viewBounds: RelBounds(20,50,200,16),
  59.         text:  "Calculates primes from"
  60. }
  61.  
  62. -----
  63. Sieve+GoBtn
  64. {
  65.     _proto: 'protoTextButton,
  66.     text: "Go...",
  67.     viewBounds: RelBounds(150,5,60,16),
  68.     buttonClickScript:func()
  69.     begin
  70.         SetValue(Status,'text ,  "");
  71.         SetValue(EStatus,'text ,  "Please wait...");
  72.         // SetValue will wait to display until end of buttonClickScript unless...
  73.         RefreshViews(); // force screen update (use judiciously/minimally)
  74.         local  x, size, i, k, prime, count, iter, long ; 
  75.         size := 8192;
  76.         long := Ticks(); // start timer
  77.  
  78.         for iter := 1 to 10 do
  79.         begin
  80.             count := 0;
  81.             x := NIL;  // to avoid memory problem of old&new arrays co-existing for a moment
  82.             x := Array(size+1, 1); // reallocating (with new initial value) seems faster than recycling&filling
  83.             for i := 1 to size do
  84.                 if x[i] = 1 then
  85.                 begin
  86.                     prime := i + i + 3;
  87.                     for k := (i+prime) to size by prime do
  88.                         x[k] := 0;
  89.                     count := count + 1;
  90.                 end;
  91.         end;        
  92.  
  93.         SetValue(SStatus,'text ,"Start:" && long);  // NumberStr optional
  94.         j := Ticks();
  95.         i := (j-long) / 60;
  96.         SetValue(Status,'text , "End  :" && j); 
  97.         SetValue(EStatus,'text ,"Elap.:" && i && "sec.");
  98.         :Notify(3,EnsureInternal("Sieve"), // avoid later "grip of death"
  99.             EnsureInternal("Num primes:" & count && "Time:" && i));
  100.     end;
  101. }
  102.  
  103.  
  104. -----
  105. Sieve+EStatus
  106. {
  107.         _proto: 'protoStaticText,
  108.         viewBounds: RelBounds(20,70,200,16),
  109.         text:  "1 to 8192, 10 times."
  110. }
  111.  
  112.  
  113. -----
  114. Sieve.about+maboutText
  115. {
  116. // about text
  117.  
  118.     viewclass: 'clParagraphView,
  119.     text: "by Serg Koren  \u000D\u " & Sieve._package.copyright & "  \u000D\u       SergK@eworld.com \u000D\u Freeware." ,
  120.     viewFlags: 3,
  121.     viewBounds: RelBounds(5,20,200,80),
  122. }
  123.  
  124.  
  125. -----
  126. Sieve.about+title
  127. {
  128. // about title
  129.  
  130.     _proto: protoStaticText,
  131.     viewBounds: RelBounds ( 20,5 ,150 ,16 ),
  132.     // reformat version to x.xx in text
  133.     text: "Sieve - Ver." &&  SubStr(NumberStr(Sieve._package.version),0,1) & "." & SubStr(NumberStr(Sieve._package.version),1,2),
  134. }
  135.  
  136. -----
  137.